home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
program
/
ny_src.zip
/
MEDIT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-26
|
4KB
|
179 lines
#include <stdio.h>
#include <string.h>
#define LEVELS 21
void dump(void);
typedef enum {HANDS,PEPPER,KNIFE,CHAIN,GUN,RIFLE,LASER_GUN,SHOTGUN,MACHINEGUN,GRANADE_LAUNCHER,BLASTER,A_BOMB} weapon;
typedef struct {
int first_enemy[LEVELS],
last_enemy[LEVELS];
} enemy_idx;
typedef struct {
char name[36];
int hitpoints,
strength,
defense;
weapon arm;
} enemy;
void
main(void)
{
FILE *justfile;
enemy erec;
enemy_idx eidx;
char key;
int num,cnt;
char nnm[36];
do {
printf("\n\nA-Add V-View E-Edit Q-Quit >");
scanf("%c",&key);
dump();
if (key=='A' || key=='a') {
printf("Name of the sucker:");
cnt=0;
do {
scanf("%c",&key);
erec.name[cnt]=key;
cnt++;
} while (key!='\n' && key!='\r' && cnt<36);
erec.name[cnt-1]=0;
if (key!='\n' && key!='\r') dump();
printf("Hitpoints:");
scanf("%d",&erec.hitpoints);
dump();
printf("Strength:");
scanf("%d",&erec.strength);
dump();
printf("Defense:");
scanf("%d",&erec.defense);
dump();
printf("Arm:");
scanf("%d",&erec.arm);
dump();
justfile=fopen("NYENM.DAT","a+b");
printf("Atpos: %d\n\n",ftell(justfile)/sizeof(enemy));
fwrite(&erec,sizeof(enemy),1,justfile);
fclose(justfile);
}
else if (key=='V' || key=='v') {
printf("\nView which record:");
scanf("%d",&num);
dump();
justfile=fopen("NYENM.DAT","rb");
fseek(justfile,num*sizeof(enemy),SEEK_SET);
fread(&erec,sizeof(enemy),1,justfile);
fclose(justfile);
printf("Name of the sucker: %s\n",erec.name);
printf("Hitpoints: %d\n",erec.hitpoints);
printf("Strength: %d\n",erec.strength);
printf("Defense: %d\n",erec.defense);
printf("Arm: %d\n",erec.arm);
}
else if (key=='E' || key=='e') {
printf("\nEdit which record:");
scanf("%d",&num);
dump();
justfile=fopen("NYENM.DAT","rb");
fseek(justfile,num*sizeof(enemy),SEEK_SET);
fread(&erec,sizeof(enemy),1,justfile);
fclose(justfile);
printf("Name of the sucker: %s\n",erec.name);
printf("Hitpoints: %d\n",erec.hitpoints);
printf("Strength: %d\n",erec.strength);
printf("Defense: %d\n",erec.defense);
printf("Arm: %d\n",erec.arm);
printf("\nName of the sucker:");
cnt=0;
do {
scanf("%c",&key);
erec.name[cnt]=key;
cnt++;
} while (key!='\n' && key!='\r' && cnt<36);
erec.name[cnt-1]=0;
if (key!='\n' && key!='\r') dump();
printf("Hitpoints:");
scanf("%d",&erec.hitpoints);
dump();
printf("Strength:");
scanf("%d",&erec.strength);
dump();
printf("Defense:");
scanf("%d",&erec.defense);
dump();
printf("Arm:");
scanf("%d",&erec.arm);
dump();
justfile=fopen("NYENM.DAT","r+b");
fseek(justfile,num*sizeof(enemy),SEEK_SET);
fwrite(&erec,sizeof(enemy),1,justfile);
fclose(justfile);
}
} while (key!='q' && key!='Q');
printf("\n\nRebuild the idx file? yn >");
scanf("%c",&key);
dump();
if (key=='y' || key=='Y') {
justfile=fopen("NYENM.IDX","rb");
fread(&eidx,sizeof(enemy_idx),1,justfile);
fclose(justfile);
for (num=0;num<=20;num++) {
printf("input first enemy for level %d, was %d :",num,eidx.first_enemy[num]);
scanf("%d",&eidx.first_enemy[num]);
printf("input last enemy for level %d, was %d :",num,eidx.last_enemy[num]);
scanf("%d",&eidx.last_enemy[num]);
dump();
}
justfile=fopen("NYENM.IDX","wb");
fwrite(&eidx,sizeof(enemy_idx),1,justfile);
fclose(justfile);
}
printf("\nDone!");
}
void
dump(void)
{
char key;
do {
scanf("%c",&key);
} while (key!='\n');
}